package sharewithus.analyzer;

import java.io.Serializable;

/**
 * 二元连词类
 * 
 * @author terry
 * 
 */
public class Bigram implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -314603672521296171L;

	private int leftWordId; // 左词id
	private int rightWordId; // 右词id
	private static final Bigram key = new Bigram();

	private Bigram() {
	}

	public int getLeftWordId() {
		return leftWordId;
	}

	public void setLeftWordId(int leftWordId) {
		this.leftWordId = leftWordId;
	}

	public int getRightWordId() {
		return rightWordId;
	}

	public void setRightWordId(int rightWordId) {
		this.rightWordId = rightWordId;
	}

	private void reset() {
		this.leftWordId = 0;
		this.rightWordId = 0;
	}

	public static synchronized Bigram getKey(int leftWordId, int rightWordId) {
		key.reset();
		key.leftWordId = leftWordId;
		key.rightWordId = rightWordId;
		return key;
	}

	public String toString(){
		return leftWordId + "@" + rightWordId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + leftWordId;
		result = prime * result + rightWordId;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Bigram other = (Bigram) obj;
		if (leftWordId != other.leftWordId)
			return false;
		if (rightWordId != other.rightWordId)
			return false;
		return true;
	}
	
	
}
